package com.example.shop.service.impl;

import com.example.shop.entity.Products;
import com.example.shop.dao.ProductsMapper;
import com.example.shop.service.ProductsService;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

/**
 * (Products)表服务实现类
 *
 * @author makejava
 * @since 2025-03-26 09:27:51
 */
@Service("productsService")
public class ProductsServiceImpl implements ProductsService {
    @Resource
    private ProductsMapper productsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param productsid 主键
     * @return 实例对象
     */
    @Override
    public Products queryById(Integer productsid) {
        return this.productsMapper.queryById(productsid);
    }


    /**
     * 新增数据
     *
     * @param products 实例对象
     * @return 实例对象
     */
    @Override
    public Products insert(Products products) {
        this.productsMapper.insert(products);
        return products;
    }

    /**
     * 修改数据
     *
     * @param products 实例对象
     * @return 实例对象
     */
    @Override
    public Products update(Products products) {
        this.productsMapper.update(products);
        return this.queryById(products.getProductsid());
    }

    /**
     * 通过主键删除数据
     *
     * @param productsid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer productsid) {
        return this.productsMapper.deleteById(productsid) > 0;
    }
}
